package gitee.derumin.lib_for_derumin.commands.suggestionproviders;

import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.server.command.ServerCommandSource;

import java.util.concurrent.CompletableFuture;

public class PlayerNameSuggestionProvider implements SuggestionProvider<ServerCommandSource> {
    public static final PlayerNameSuggestionProvider PROVIDER = new PlayerNameSuggestionProvider();
    @Override
    public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) {
        String[] names = context.getSource().getServer().getPlayerNames();
        for (String name : names){
            builder.suggest(name);
        }
        return builder.buildFuture();
    }
}
